package net.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Map;

import freemarker.template.utility.Execute;

import net.util.RWFile;
import net.vo.ProValues;

public class BaseDAO implements ProValues {

	protected Connection conn;
	protected Statement stmt;
	protected PreparedStatement ps;
	protected ResultSet rs;

	protected Connection openConnection() {
		try {
			Class.forName(conParam.get("jdbc.driver"));
			return DriverManager.getConnection(conParam.get("jdbc.url"),
					conParam.get("jdbc.username"),
					conParam.get("jdbc.password"));
		} catch (Exception e) {
			System.out.println("找不到驱动程序类 ，加载驱动失败！");
			e.printStackTrace();
		}
		return null;
	}

	static {
		System.out.println(CONN_FILE);
		conParam = RWFile.getProperties(CONN_FILE);
	}

	protected void close() {
		try {
			if (rs != null) {
				rs.close();
				rs = null;
			}
			if (ps != null) {
				ps.close();
				ps = null;
			}
			if (stmt != null) {
				stmt.close();
				stmt = null;
			}
			if (conn != null) {
				conn.close();
				conn = null;
			}
		} catch (Exception e) {
			System.out.println("close Exception");
		}
	}
	
	private static Map<String, String> conParam;

}
